﻿using BasicInformation.ApiRead.Application.Command.Depot;
using BasicInformation.Domain;
using BasicInformation.Dtos;
using BasicInformation.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BasicInformation.ApiRead.Controllers
{
    /// <summary>
    /// 仓库管理处理类——读
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    //[Authorize]
    public class DepotController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<DepotController> logger;

        public DepotController(IMediator mediator,ILogger<DepotController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 仓库管理显示分页查询接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<DepotDTO>> GetDepot([FromQuery]GetDepotCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 仓库类型查询接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<DepotTypeModel>> GetDepotType([FromQuery]GetDepotTypeCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 全局异常过滤器
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpGet]
        public string Text()
        {
            try
            {
                logger.LogInformation("测试日志");
                throw new Exception("故意报错");
            }
            catch (Exception ex)
            {

                logger.LogError("测试日志==>"+ex.Message);
                throw new Exception("故意报错");
            }
        }
    }
}
